aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-18 13:09:41 -0700
committerAdam Soltys <[email protected]>2024-08-18 22:15:05 -0700
commit250c7f9e9621d9eae1a3b364dd7d0716e7c49e31 (patch)
tree5cf0250363d11fb33414d8cae4f583e186247123 /src/routes/(app)/[username]
parente1cdf7d3c4c7b737d779efdf4236fb55fc0e4229 (diff)
downloadcoinos-ui-250c7f9e9621d9eae1a3b364dd7d0716e7c49e31.tar.gz
coinos-ui-250c7f9e9621d9eae1a3b364dd7d0716e7c49e31.zip
ecash
Diffstat (limited to 'src/routes/(app)/[username]')
-rw-r--r--src/routes/(app)/[username]/(profile)/+page.svelte2
-rw-r--r--src/routes/(app)/[username]/ecash/[...token]/+page.server.js5
-rw-r--r--src/routes/(app)/[username]/ecash/[...token]/+page.svelte61
-rw-r--r--src/routes/(app)/[username]/invoice/[id]/+page.svelte142
-rw-r--r--src/routes/(app)/[username]/payments/[...page]/+page.svelte2
-rw-r--r--src/routes/(app)/[username]/receive/[...param]/+page.server.js22
-rw-r--r--src/routes/(app)/[username]/receive/[...param]/+page.svelte136
7 files changed, 283 insertions, 87 deletions
diff --git a/src/routes/(app)/[username]/(profile)/+page.svelte b/src/routes/(app)/[username]/(profile)/+page.svelte
index 1dd8f573..2dfd4979 100644
--- a/src/routes/(app)/[username]/(profile)/+page.svelte
+++ b/src/routes/(app)/[username]/(profile)/+page.svelte
@@ -147,7 +147,7 @@
class="rounded-2xl border py-5 px-6 font-bold hover:opacity-80 flex bg-primary grow"
>
<div class="mx-auto flex gap-2">
- <Icon icon="numpad" style="w-8" />
+ <Icon icon="receive" style="w-8" />
<div class="my-auto">{$t("user.dashboard.receive")}</div>
</div>
</button>
diff --git a/src/routes/(app)/[username]/ecash/[...token]/+page.server.js b/src/routes/(app)/[username]/ecash/[...token]/+page.server.js
new file mode 100644
index 00000000..01b5521c
--- /dev/null
+++ b/src/routes/(app)/[username]/ecash/[...token]/+page.server.js
@@ -0,0 +1,5 @@
+export let load = async ({ cookies, params, parent }) => {
+ let { rates, user } = await parent();
+ let token = params.token || cookies.get("ecash");
+ return { rates, token, user };
+};
diff --git a/src/routes/(app)/[username]/ecash/[...token]/+page.svelte b/src/routes/(app)/[username]/ecash/[...token]/+page.svelte
new file mode 100644
index 00000000..d02102a6
--- /dev/null
+++ b/src/routes/(app)/[username]/ecash/[...token]/+page.svelte
@@ -0,0 +1,61 @@
+<script>
+ import { getDecodedToken } from "@cashu/cashu-ts";
+ import { copy, sats, f, s } from "$lib/utils";
+ import { t } from "$lib/translations";
+ import Icon from "$comp/Icon.svelte";
+ export let data;
+ let { rates, user, token } = data;
+ let { currency } = user;
+ let rate = rates[currency];
+ let { proofs } = getDecodedToken(token).token[0];
+ let amount = proofs.reduce((a, b) => a + b.amount, 0);
+ $: amountFiat = parseFloat(((amount * rate) / sats).toFixed(2));
+</script>
+
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
+ {$t("payments.ecash")}
+ </h1>
+
+ {#if amount > 0}
+ <div class="text-center font-bold text-2xl">
+ <div>
+ {f(amountFiat, currency)}
+ </div>
+ <div>
+ <span class="text-secondary font-normal text-xl"
+ >⚡️{`${s(amount)}`}</span
+ >
+ </div>
+ </div>
+ {/if}
+
+ <div class="flex flex-wrap gap-2 text-xl">
+ <a href={`/qr/${encodeURIComponent(token)}`} class="contents">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2"
+ >
+ <Icon icon="qr" style="w-8 my-auto invert" />
+ <div class="my-auto">{$t("payments.qr")}</div>
+ </button>
+ </a>
+
+ <a href={`/voucher/${encodeURIComponent(token)}`} class="contents">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full justify-center gap-2"
+ >
+ <Icon icon="receive" style="w-8 my-auto" />
+ <div class="my-auto">{$t("payments.redeem")}</div>
+ </button>
+ </a>
+ </div>
+
+ <button
+ class="border rounded p-6 w-full break-all text-xl hover:bg-slate-100"
+ on:click={() => copy(token)}
+ >
+ {token}
+ </button>
+</div>
diff --git a/src/routes/(app)/[username]/invoice/[id]/+page.svelte b/src/routes/(app)/[username]/invoice/[id]/+page.svelte
index 1a569039..f28faf99 100644
--- a/src/routes/(app)/[username]/invoice/[id]/+page.svelte
+++ b/src/routes/(app)/[username]/invoice/[id]/+page.svelte
@@ -1,5 +1,5 @@
<script>
- import { enhance } from "$app/forms";
+ import { enhance } from "$app/forms";
import { send } from "$lib/socket";
import {
btc,
@@ -21,6 +21,7 @@
import Icon from "$comp/Icon.svelte";
import Heart from "$comp/Heart.svelte";
import Image from "$comp/Image.svelte";
+ import Numpad from "$comp/Numpad.svelte";
import { t } from "$lib/translations";
import { goto, invalidate } from "$app/navigation";
@@ -117,6 +118,22 @@
goto(`./${id}?options=true`, { invalidateAll: true, noScroll: true });
};
+
+ let setAmount = async () => {
+ settingAmount = false;
+ invoice.amount = amount;
+ ({ id } = await post(`/${username}/invoice`, {
+ invoice,
+ user: { username, currency },
+ }));
+
+ goto(`./${id}?options=true`, { invalidateAll: true, noScroll: true });
+ };
+
+ let settingAmount;
+ let toggleAmount = () => (settingAmount = !settingAmount);
+ let fiat;
+ let submit;
</script>
<div class="invoice container mx-auto max-w-xl px-4 space-y-2">
@@ -177,50 +194,50 @@
</div>
{/if}
- <button
- type="button"
- class="flex gap-2 text-center break-all rounded-2xl hover:opacity-80 py-5 px-6 w-full mx-auto justify-center border text-xl whitespace-nowrap"
- on:click={() => copy(txt)}
- >
- <Icon icon="copy" style="w-8 my-auto" />
- <div class="my-auto">
- {txt.substr(0, 11)}..{txt.substr(-10)}
- </div>
- </button>
+ <div class="text-secondary space-y-1">
+ <button
+ type="button"
+ class="flex gap-2 text-center break-all rounded-2xl hover:opacity-80 py-5 px-6 w-full mx-auto justify-center border text-xl whitespace-nowrap"
+ on:click={() => copy(txt)}
+ >
+ <Icon icon="copy" style="w-8 my-auto" />
+ <div class="my-auto">
+ {$t("payments.copy")}
+ {txt.substr(0, 11)}...{txt.substr(-6)}
+ </div>
+ </button>
- <div
- class="w-full flex justify-center gap-2 flex-wrap text-secondary text-xl"
- >
- <a href={link} class="w-full">
+ {#if user.id === invoice.user.id}
<button
- class="w-full flex justify-center rounded-2xl border py-5 px-6 hover:opacity-80"
+ class="w-full flex justify-center rounded-2xl border py-5 px-6 hover:opacity-80 text-xl"
+ on:click={toggleAmount}
>
- <Icon icon="mobile" style="mr-1 w-8" />
- <div class="my-auto">{$t("payments.openLink")}</div>
+ <Icon icon="edit" style="mr-1 w-8" />
+ <div class="my-auto">{$t("payments.setAmount")}</div>
</button>
- </a>
-
- <button
- class="w-full flex justify-center rounded-2xl border py-5 px-6 hover:opacity-80"
- on:click={() => ($showQr = !$showQr)}
- >
- <Icon icon="qr" style="w-8 mr-1 invert my-auto" />
- <div class="my-auto">
- {$showQr ? $t("payments.hide") : $t("payments.show")}
- {$t("payments.qr")}
- </div></button
- >
+ {:else}
+ <a href={link} class="w-full">
+ <button
+ class="w-full flex justify-center rounded-2xl border py-5 px-6 hover:opacity-80"
+ >
+ <Icon icon="mobile" style="mr-1 w-8" />
+ <div class="my-auto">{$t("payments.openLink")}</div>
+ </button>
+ </a>
+ {/if}
- <!-- <button -->
- <!-- class="w-full flex justify-center rounded-2xl border py-3 px-5 hover:opacity-80 text-lg" -->
- <!-- on:click={() => (showOptions = !showOptions)} -->
- <!-- > -->
- <!-- <Icon icon="settings" style="w-8 mr-1 my-auto" /> -->
- <!-- <div class="my-auto"> -->
- <!-- {showOptions ? $t("payments.hide") : $t("payments.show")} -->
- <!-- {$t("payments.options")} -->
- <!-- </div></button -->
- <!-- > -->
+ <div class="w-full flex justify-center gap-2 flex-wrap text-xl">
+ <button
+ class="w-full flex justify-center rounded-2xl border py-5 px-6 hover:opacity-80"
+ on:click={() => ($showQr = !$showQr)}
+ >
+ <Icon icon="qr" style="w-8 mr-1 invert my-auto" />
+ <div class="my-auto">
+ {$showQr ? $t("payments.hide") : $t("payments.show")}
+ {$t("payments.qr")}
+ </div></button
+ >
+ </div>
</div>
<div class="flex justify-around text-secondary">
@@ -266,8 +283,53 @@
</div>
</div>
{/if}
+
+ {#if user.id === invoice.user.id}
+ <a href={`/voucher`}>
+ <button
+ class="flex gap-2 text-center break-all rounded-2xl hover:opacity-80 py-5 px-6 w-full mx-auto justify-center border text-xl whitespace-nowrap text-secondary"
+ >
+ <Icon icon="voucher" style="w-8 my-auto" />
+ <div class="my-auto">
+ {$t("payments.redeemVoucher")}
+ </div></button
+ >
+ </a>
+ {/if}
</div>
+{#if settingAmount}
+ <div
+ class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-20"
+ >
+ <div
+ class="relative top-1/3 mx-auto p-12 border w-96 shadow-lg rounded-md bg-white space-y-5"
+ >
+ <form submit={setAmount}>
+ <Numpad bind:amount bind:currency bind:rate bind:fiat bind:submit />
+ <div class="w-full flex flex-wrap gap-2">
+ <button
+ type="submit"
+ on:click={setAmount}
+ class="border-2 border-black rounded-xl font-semibold mx-auto py-3 w-40 hover:opacity-80 mx-auto bg-black text-white w-full"
+ >
+ <div class="my-auto">Ok</div>
+ </button>
+ <button
+ bind:this={submit}
+ type="button"
+ class="border-2 border-black rounded-xl font-semibold mx-auto py-3 w-40 hover:opacity-80 mx-auto w-full"
+ on:click={toggleAmount}
+ on:keydown={toggleAmount}
+ >
+ <div class="my-auto">Cancel</div>
+ </button>
+ </div>
+ </form>
+ </div>
+ </div>
+{/if}
+
<style>
.invoice {
view-transition-name: invoice;
diff --git a/src/routes/(app)/[username]/payments/[...page]/+page.svelte b/src/routes/(app)/[username]/payments/[...page]/+page.svelte
index 7e2bac9f..9f8dd5df 100644
--- a/src/routes/(app)/[username]/payments/[...page]/+page.svelte
+++ b/src/routes/(app)/[username]/payments/[...page]/+page.svelte
@@ -203,7 +203,7 @@
</div>
{:else}
<div class="text-secondary flex">
- {#if p.type === types.lightning}
+ {#if [types.ecash, types.lightning].includes(p.type)}
<div class="text-3xl">⚡️</div>
{:else if p.type === types.bitcoin}
<div class="my-auto mr-1">
diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.server.js b/src/routes/(app)/[username]/receive/[...param]/+page.server.js
index a6e59175..c3b6ca64 100644
--- a/src/routes/(app)/[username]/receive/[...param]/+page.server.js
+++ b/src/routes/(app)/[username]/receive/[...param]/+page.server.js
@@ -1,15 +1,19 @@
-import { auth, get } from "$lib/utils";
+import { redirect } from "@sveltejs/kit";
+import { auth, post } from "$lib/utils";
import invoice from "$lib/invoice";
-export let load = async ({ cookies, params }) => {
- let id = params.param;
+export let load = async ({ cookies, parent }) => {
+ let { user, rates } = await parent();
- let request;
- if (id) ({ request } = await get(`/request/${id}`, auth(cookies)));
+ let invoice = {
+ type: "lightning",
+ rate: rates[user.currency],
+ };
- return { ...params, request };
-};
+ invoice = await post("/invoice", { invoice, user }, auth(cookies));
+ let { id } = invoice;
-export const actions = {
- default: invoice,
+ if (invoice.memoPrompt && !invoice.memo) {
+ redirect(307, `/${user.username}/invoice/${id}/memo`);
+ } else redirect(307, `/${user.username}/invoice/${id}`);
};
diff --git a/src/routes/(app)/[username]/receive/[...param]/+page.svelte b/src/routes/(app)/[username]/receive/[...param]/+page.svelte
index d643d181..f9267105 100644
--- a/src/routes/(app)/[username]/receive/[...param]/+page.svelte
+++ b/src/routes/(app)/[username]/receive/[...param]/+page.svelte
@@ -1,52 +1,116 @@
<script>
- import Icon from "$comp/Icon.svelte";
- import Numpad from "$comp/Numpad.svelte";
- import Toggle from "$comp/Toggle.svelte";
- import { t } from "$lib/translations";
- import { enhance } from "$app/forms";
import { page } from "$app/stores";
- import { requestRedirect } from "$lib/store";
+ import { fly } from "svelte/transition";
+ import { enhance } from "$app/forms";
+ import { tick } from "svelte";
import { browser } from "$app/environment";
+ import { t } from "$lib/translations";
+ import AppHeader from "$comp/AppHeader.svelte";
+ import Avatar from "$comp/Avatar.svelte";
+ import Icon from "$comp/Icon.svelte";
+ import Spinner from "$comp/Spinner.svelte";
+ import { back, fail, focus } from "$lib/utils";
export let data;
- let type = "lightning";
-
- if ($page.params.param === "bitcoin") type = "bitcoin";
+ export let form;
+ data.subject = data.user;
- let { request } = data;
+ let { contacts } = data;
+ let w;
- let amount;
+ let el, text;
- let lightning = true;
- let { currency, username, prompt } = data.subject;
- let { rates, user } = data;
- let submit;
+ let keypress = (e) => e.key === "Enter" && (e.preventDefault() || el.click());
- $: rate = rates[currency];
- $: type = lightning ? "lightning" : "bitcoin";
+ let paste = async () => {
+ text = await navigator.clipboard.readText();
+ };
</script>
-<form
- method="POST"
- class="flex justify-center items-center mb-3 px-3"
- use:enhance
->
- <input type="hidden" name="amount" value={amount} />
- <input type="hidden" name="currency" value={currency} />
- <input type="hidden" name="username" value={username} />
- <input type="hidden" name="type" value={type} />
- <input type="hidden" name="rate" value={rate} />
- <input type="hidden" name="prompt" value={prompt} />
+<svelte:window bind:innerWidth={w} />
+
+<AppHeader {data} />
+<div class="container px-4 max-w-lg mx-auto space-y-5 mt-20">
+ <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold">
+ {$t("payments.send")}
+ </h1>
+
+ <form method="POST" use:enhance class="space-y-2 text-xl">
+ {#if form?.error}
+ <div class="mb-5">
+ <div class="text-red-600">
+ {$t("error.unrecognizedInput")}
+ </div>
+ </div>
+ {/if}
+
+ <div class="mb-2">
+ <textarea
+ use:focus
+ name="text"
+ placeholder={$t("user.send.placeholder")}
+ on:keypress={keypress}
+ class="w-full p-4 border rounded-xl h-48 text-xl"
+ bind:value={text}
+ autocapitalize="none"
+ />
+ </div>
+
+ <div class="flex gap-2">
+ <a href="/scan" class="w-full">
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ >
+ <Icon icon="camera" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.scan")}</div>
+ </button>
+ </a>
+
+ <button
+ type="button"
+ class="flex border rounded-2xl px-6 py-5 font-bold hover:opacity-80 w-full bg-primary justify-center"
+ on:click={paste}
+ >
+ <Icon icon="paste" style="mr-2 w-6 my-auto" />
+ <div class="my-auto">{$t("user.send.paste")}</div>
+ </button>
+ </div>
- <div class="space-y-3 w-[300px] mx-auto">
- <Numpad bind:amount bind:currency bind:rate {submit} />
<button
- bind:this={submit}
+ bind:this={el}
type="submit"
- class="bg-black text-white rounded-xl w-full h-[48px] flex justify-center items-center font-semibold
- opacity-100 hover:opacity-80"
+ class="bg-black text-white border rounded-2xl px-6 py-5 w-full font-bold"
>
- {$t("payments.next")}
+ {$t("user.send.next")}
</button>
- </div>
-</form>
+ </form>
+
+ {#if contacts.length}
+ <div class="space-y-5">
+ <h1 class="px-3 md:px-0 text-2xl font-semibold mt-10">
+ {$t("user.send.contacts")}
+ </h1>
+ <div>
+ {#each contacts as c}
+ <a href={`/pay/${c.username}`}>
+ <div
+ class="border-b p-2 last:border-b-0 hover:bg-gray-100 rounded-2xl"
+ >
+ <div class="flex">
+ <div>
+ <div class="flex">
+ <Avatar user={c} size={20} disabled={true} />
+ <div class="my-auto text-left">
+ <p class="ml-1 text-lg break-words">{c.username}</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </a>
+ {/each}
+ </div>
+ </div>
+ {/if}
+</div>